<script setup lang="ts">
import { ref } from 'vue'
let msg = ref('');
let showMsg = ref(false);
const openMsg = (resMsg,times = 1000) => {
	showMsg.value = true;
	msg.value = resMsg;
	setTimeout(() => {
		showMsg.value = false;
	}, times);
}
defineExpose(
	{
		openMsg,
		msg,
		showMsg
	}
)
</script>

<template>
	<Transition name="fade">
		<div class="msg" v-show='showMsg'>
			<div class="msginfo">
				<div class="icon">
					<svg viewBox="0 0 24 24" width="24" height="24" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round">
						<circle cx="12" cy="12" r="10"></circle>
						<line x1="12" y1="8" x2="12" y2="12"></line>
						<line x1="12" y1="16" x2="12.01" y2="16"></line>
					</svg>
				</div>
				<div class="message">{{ msg }}</div>
			</div>
		</div>
	</Transition>
</template>

<style lang="scss">
/* 改进的动画效果 */
.fade-enter-active {
	transition: all 0.3s ease-out;
}

.fade-leave-active {
	transition: all 0.3s ease-in;
}

.fade-enter-from {
	opacity: 0;
	transform: translateY(-20px);
}

.fade-leave-to {
	opacity: 0;
	transform: translateY(20px);
}

.msg {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background: rgba(0, 0, 0, 0.6);
	display: flex;
	justify-content: center;
	align-items: center;
	z-index: 99999;
	backdrop-filter: blur(2px);
	
	.msginfo {
		min-width: 300px;
		max-width: 80%;
		padding: 20px;
		background: rgba(255, 255, 255, 0.95);
		border-radius: 12px;
		box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
		display: flex;
		flex-direction: column;
		align-items: center;
		gap: 15px;
		animation: pulse 1.5s infinite ease-in-out;
		
		.icon {
			color: #409EFF;
			display: flex;
			justify-content: center;
			align-items: center;
			
			svg {
				width: 40px;
				height: 40px;
			}
		}
		
		.message {
			color: #303133;
			font-size: 18px;
			font-weight: 500;
			text-align: center;
			line-height: 1.5;
			word-break: break-word;
		}
	}
}

@keyframes pulse {
	0% {
		transform: scale(1);
	}
	50% {
		transform: scale(1.03);
	}
	100% {
		transform: scale(1);
	}
}
</style>
